﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WuDada.Core.Post;
using WuDada.Core.Post.Service;
using WuDada.Core.Post.Domain;

public partial class contactus : System.Web.UI.Page
{
    private PostFactory m_PostFactory;
    private IPostService m_PostService;
    private HttpHelper m_HttpHelper;
    private WebMailService m_WebMailService;

    //聯絡我們 m_NodeId = 42
    private int m_NodeId = 42;

    protected void Page_Load(object sender, EventArgs e)
    {
        m_PostFactory = new PostFactory();
        m_PostService = m_PostFactory.GetPostService();
        m_HttpHelper = new HttpHelper();
        m_WebMailService = new WebMailService();

        if (!IsPostBack)
        {            
        }
    }

    protected void btnSend_Click(object sender, EventArgs e)
    {
        PostVO postVO = new PostVO();
        UIHelper.FillVO(PanelUI, postVO);
        postVO.Node = m_PostService.GetNodeById(m_NodeId);
        postVO.CreatedDate = DateTime.Now;
        postVO.CreatedBy = m_HttpHelper.GetUserIp(Context);
        postVO.Flag = 1;
        postVO = m_PostService.CreatePost(postVO);

        //發信
        m_WebMailService.SendMail_ToContactor_ByPost(postVO);

        ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "js", JavascriptUtil.AlertJS("已送出。"), false);
        ClearUI();
    }

    private void ClearUI()
    {
        UIHelper.ClearUI(PanelUI);
    }
}